import * as types from '../consts/mutation-types'

export default {
    state: {
        playing: false, //播放状态
        playlist: [], //播放列表
        currentIndex: -1
    },
    mutations: {
        //修改播放状态
        [types.SET_PLAYING](state, playing) {
            state.playing = playing
        },
        //修改播放列表
        [types.SET_PLAYLIST](state, playlist) {
            state.playlist = playlist
        },
        //修改当前音乐索引
        [types.SET_CURRENTINDEX](state, currentIndex) {
            state.currentIndex = currentIndex
        },

    },
    actions: {
        //修改播放状态
        setPlay(context, playing) {
            context.commit(types.SET_PLAYING, playing);
        },
        //修改播放列表
        setPlaylist(context, playlist) {
            context.commit(types.SET_PLAYLIST, playlist);
        },
        //修改当前音乐索引
        setCurrentIndex(context, currentIndex) {
            context.commit(types.SET_CURRENTINDEX, currentIndex);
        },
    },
    getters: {
        currentMusic: state => {
            return state.playlist[state.currentIndex] || {};
        },
        currentIndex: state => state.currentIndex,
        playlist: state =>state.playlist,
    }
}